<template>
    <!-- <div style="padding:0px;"> -->
        <!-- <img :disabled="disabled" :style="{cursor:(disabled?'not-allowed':'pointer')}"
              :class="cls" @click="handleClick"> -->
              <i :class="commonIconStyle + ' ' + cls + ' ' + malr5" :title="title"  @click="handleClick" :disabled="disabled" :style="{cursor:(disabled?'not-allowed':'pointer')}"></i>
    <!-- </div> -->
</template>
<script>
    import Service from '../../../services/common.service'
    export default {
        lock: Boolean,
        _params: Object,
        _url: String,
        data() {
            return {
                commonIconStyle:'commonIconStyle',
                malr5: 'malr5'
            }
        },
        created: function () {
        },
        methods: {
            handleClick(evt) {
                const me = this;
                if (me.lock || me.disabled) {
                    return;
                }
                me.$emit('click', evt, me);
                if (me.autopost) {
                    me.post();
                }
            },
            post(url, params) {
                const me = this;
                if (me.lock) {
                    return;
                }
                me._params = params ? params : me.params;
                me._url = url ? url : me.url;

                if (me._url && me._params) {
                    me.lock = true;
                    Service.post(me._url, me._params).then(res => {
                        if (res.data.succeeded == true) {
                            me.$emit('callback', res);
                        }
                        me.lock = false;
                    })
                }

            }
        },
        props: {
            src: {
                type:String,
                default: ''
            },
            cls:{
                type:String,
                default:'detailIcon'
            },
            url: String,
            params: Object,
            disabled: Boolean,
            autopost: {
                type: Boolean,
                default: false
            },
            title:String
        },
    }
</script>
